// MemDC.cpp : implementation file
//

#include "stdafx.h"
#include "MemDC.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMemDC

CMemDC::CMemDC()
{
	m_bInit			= false;
	m_pOldBitmap	= NULL;
	m_unIndex		= 0;
}

CMemDC::~CMemDC()
{
	if(m_bInit) {
		SelectObject(m_pOldBitmap);
		DeleteObject(m_bmpBuffer);
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMemDC member functions

bool CMemDC::Init(CDC *pDC, int wd, int ht, UINT Index)
{
	if(m_bInit) return false;

	CreateCompatibleDC(pDC);
	m_bmpBuffer.CreateCompatibleBitmap(pDC, wd, ht);
	m_pOldBitmap = (CBitmap *)SelectObject(&m_bmpBuffer);
	m_bInit = true;

	m_unIndex = Index;

	return true;
}

void CMemDC::DeInit()
{
	if(!m_bInit) return;

	DeleteObject(m_bmpBuffer);

	SelectObject(m_pOldBitmap);
	DeleteDC();
}